package Year22_Month07.day06;

public class 柠檬水找零 {
    public boolean lemonadeChange(int[] bills) {
        int fiveCount = 0;
        int tenCount = 0;
        for (int i = 0; i < bills.length; i++) {
            //如果给的5元。直接收下
            if(bills[i] == 5){
                fiveCount++;
            }else if(bills[i] == 10){//给的10元，找一个5，收下10
                fiveCount--;
                tenCount++;
            }else{
                //给了20进行判断
                //如果有10元，10--，5--
                if(tenCount > 0){
                    tenCount--;
                    fiveCount--;
                }else {
                    fiveCount -= 3;
                }
            }
            if(fiveCount < 0 || tenCount < 0){
                return false;
            }
        }
        return true;
    }
}
